Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
Cómo asignar las variables de una matriz a elementos en querySelectorall [Javascript puro]

Estoy tratando de asignar los valores de una matriz a los elementos que fueron seleccionados por la función querySelectorAll. Se agradece cualquier ayuda. El código que estoy tratando de escribir es que cuando el punto de vista del navegador está por debajo de 768 px, el texto cambia a los de la matriz, probé todos los métodos que se me ocurrieron.

 var newb = document.querySelectorAll("#buttonsize button") var arSizes = ["Small", "Medium", "Large", "X-Large", "Large", "XX-Large"] for(var i = 0; i < arSizes.length; i++) { newb[i].textContent = arSizes[i] }

da este error

TypeError no capturado: no se pueden establecer propiedades de indefinido (estableciendo 'textContent')

También intenté hacer newb.textContent y también usar una función forEach .

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Creo que no tiene suficientes botones en html, así que mejor lista o botones en primer lugar

 var newb = document.querySelectorAll("#buttonsize button"); var arSizes = ["Small", "Medium", "Large", "X-Large", "Large", "XX-Large"]; Array.from(newb).forEach((btnEl, index) => { btnEl.textContent = arSizes[index] });
 <div id="buttonsize"> <button>1</button> <button>2</button> <button>3</button> <button>4</button> <button>5</button> <button>6</button> </div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!